function fun(num, k){
    let arr = []
    let ans = []
    function stop(index){
        if (arr.length == k) {
            ans.push(arr.slice())
            return
        }
        for (let i = index; i < num.length; i++) {
            arr.push(num[i])
            stop(i+1)
            arr.pop()
        }
    }
    stop(0)
    return ans
}

let ans = fun([1,2,3,4], 3)
function last(n){
    let num = 0
    for (let i = 0; i < ans.length; i++) {
        if(Math.abs(ans[i][0] - ans[i][1]) <= n && Math.abs(ans[i][0] - ans[i][2]) <= n && Math.abs(ans[i][1] - ans[i][2]) <= n ){
            num++
        }
    }
    return num
}
console.log(last(3),  ans);
